package com.candy.control;

import com.candy.modal.UserLoginModal;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author donglin
 * @Title:
 * @类名: ${NAME}
 * @date 2020/8/19
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //设置request和response编码格式--防止中文乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //使用request方法：getParameter获取表单数据
        String adminName= req.getParameter("adminName");
        String adminPwd= req.getParameter("adminPwd");
        System.out.println("登录的用户名："+adminName+"，登录的密码："+adminPwd);
        UserLoginModal useM=new UserLoginModal();
       boolean isOk= useM.isLogined(adminName,adminPwd);
       if(isOk){
           req.getSession().setAttribute("loginedName",adminName);
           req.getRequestDispatcher("logined.jsp").forward(req,resp);
       }else{
           resp.sendRedirect("index.jsp");
       }






    }


}
